package com.xuan.juc.lock8;

import java.util.concurrent.TimeUnit;

public class LockTest1 {
    public static void main(String[] args) throws InterruptedException {
        Phone phone = new Phone();

        new Thread(()->{
            phone.sendMsg();
        },"A").start();

        TimeUnit.SECONDS.sleep(1);
        new Thread(()->{
            phone.call();
        },"B").start();
    }
}


class Phone{

    // synchronized 锁对象是方法的调用者！
    // 2个方法用的是同一个锁 谁先拿到谁执行
    public synchronized void sendMsg(){
        System.out.println("sendMsg");
    }

    public synchronized void call(){
        System.out.println("call");
    }

    public void hello(){
        System.out.println("hello");
    }
}
